import Vue from "vue";
import VueRouter from "vue-router";
import Chat from "../views/tab_bar/part/Chat.vue";

Vue.use(VueRouter);

//解决 Uncaught (in promise) Error: Navigation cancelled from “/xx” to “/xx” with a new navigation.
//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login/Login.vue"),
  },
  {
    path: "/",
    name: "chat",
    component: Chat,
    meta: {
      showTab: true,
      keepAlive: true
    }
  },
  {
    path: "/me",
    name: "me",
    component: () => import("../views/tab_bar/part/Me.vue"),
    meta: {
      showTab: true,
      keepAlive: true
    }
  },
  {
    path: "/find",
    name: "find",
    component: () => import("../views/tab_bar/part/Find.vue"),
    meta: {
      showTab: true,
      keepAlive: true
    }
  },
  {
    path: "/contacts",
    name: "contacts",
    component: () => import("../views/tab_bar/part/Contacts.vue"),
    meta: {
      showTab: true,
      keepAlive: true
    }
  },
  {
    path: "/commonSearch",
    name: "commonSearch",
    component: () => import("../views/search/CommonSearch.vue"),
  },
  {
    path: "/chatRoom",
    name: "chatRoom",
    component: () => import("../views/chat/ChatRoom.vue"),
  },

  {
    path: "/selfInfo",
    name: "selfInfo",
    component: () => import("../views/me/part/SelfInfo.vue"),
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes
});

export default router;
